package org.tinygroup.springmvc.handleradapter;

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;
import org.tinygroup.weblayer.WebContext;
import org.tinygroup.weblayer.webcontext.util.WebContextUtil;


/**
 * WebContext类型参数组装
 * @author renhui
 *
 */
public class WebContextWebArgumentResolver implements WebArgumentResolver {

	@Override
	public Object resolveArgument(MethodParameter methodParameter,
			NativeWebRequest webRequest) throws Exception {
		if(WebContext.class.isAssignableFrom(methodParameter.getParameterType())){
			return WebContextUtil.getWebContext(webRequest.getNativeRequest(HttpServletRequest.class));
		}
		return WebArgumentResolver.UNRESOLVED;
	}

}
